// pages/me/me.js
let app = getApp();
import util from '../../../utils/util.js';
import WxParse from '../../../libs/wxParse/wxParse.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[
      // {title:'我的三人拼',srcImg:'../../../images/me/right_arrows.png'},
      // {title:'我的人人拼',srcImg:'../../../images/me/right_arrows.png'},


      {title:'我的订单',srcImg:'../../../images/me/right_arrows.png'},
      {title:'在线客服',srcImg:'../../../images/me/right_arrows.png'}
    ],
    user:{},
    hasPhone:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.panduan()
    this.getmeBackImg()
    this.phoneShow()
    let hasPhone = wx.getStorageSync('hasPhone') || false
    this.setData({
      hasPhone
    })
  },


  phoneShow() {
    let self = this
    util.request(util.apiUrl + 'xcx.pin.banner', 'POST', {
      id: [119]
    }).then(res => {
      console.log('getmeBackImg', res.data[119])
    }).catch(err => {
      console.log(err)
      let arr = err.data[119]
      if (arr.length > 0) {
        self.setData({
          'showing': arr
        })
      }
    });
  },



  getmeBackImg(){
    let self = this
    util.request(util.apiUrl + 'xcx.pin.banner', 'POST', {
      id: [119]
    }).then(res => {
      console.log('getmeBackImg', res.data[119])
    }).catch(err => {
      console.log(err)
      let arr = err.data[119]
      if (arr.length > 0){
        self.setData({
          'me_back': arr[3].ad_code
        })
      }
    });
  },
  
  getUserInfo(){
    let user = wx.getStorageSync('user');  //获取缓存Openid
    this.setData({user})
  },
  panduan(){
    util.request(util.apiUrl + 'ecapi.consignee.list', 'POST').then(res => {
    }).catch(err => {
      util.notLogin(err);
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   this.getUserInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  //跳转拼团页面
  jumpTo_indexPage(){
    wx.redirectTo({
      url: '../index/index'
    })
  },

  //list 跳转
  list_Jump(Param){

    let index = Param.target.dataset.index
    switch(index){
      case 0:jumpTo_indexPage();
      break;
      case 1:jumpTo_myOrderPage();
      break;
    }
    //我的三人拼 if(index == 0)
    function jumpTo_indexPage(){
      wx.navigateTo({
        url: '../myOrder/myOrder'
      })
    }
    
    //我的费送单 if(index == 1)
    function jumpTo_myOrderPage(){
      wx.navigateTo({
        url: '../myOrder/myOrder'
      })
    }
  },
  getPhoneNumber: function (e) {
    // console.log(e.detail.errMsg)
    // console.log(e.detail.iv)
    // console.log(e.detail.encryptedData)
    if (e.detail.errMsg == 'getPhoneNumber:fail user deny'){

      wx.showToast({
        title: '您取消手机号授权',
        icon: 'none',
        duration: 2000
      })

      this.setData({
        'hasPhone': false
      })
      wx.setStorageSync('hasPhone', false)
    }else{
      let sessionKey = wx.getStorageSync("session_key") || ""
      util.request(util.apiUrl + 'xcx.pin.phoneshouquan', 'POST', {
        "sessionKey": sessionKey,
        "encryptedData": e.detail.encryptedData,
        "iv": e.detail.iv
      }).then(res => {
        console.log(res)
        if ( res.error_code == 0 ){
          this.setData({
            'hasPhone': true
          })
          wx.setStorageSync('hasPhone', true)
        }
      }).catch(err => {
        let msg = err.data.msg
        wx.showToast({
          title: msg,
          icon: 'none',
          duration: 2000
        })
      });
    }
  } 
})